<template>
  <parentSelect
    ref="controlInst"
    getUrl="/base/warehouse/listForSelect"
    @change="_change"
    :value="value"
    :valueDisplay="valueDisplay"
    :disabled="disabled"
    :isVuex="true"
    :vuexType="vuexType"
    :vuexGetKey="vuexGetKey"
    :keyLabel="keyLabel"
    :dataFilter="_dataFilter"
  />
</template>

<script>
import parentSelect from '@/components/custom/bus/select/parentSelect.vue'

export default {
  desc: '仓库选择',
  name: 'warehouseSelect',
  components: {
    parentSelect
  },
  props: {
    /**
     * @Description：idNe 需要排除的仓库id
     */
    flagCenter: {
      type: Boolean,
      default: () => null
    },
    /**
     * @Description：true 中心仓库
     */
    idNe: {
      type: String,
      default: () => null
    },
    /**
     * @Description：true 中心仓库
     */
    value: {
      type: String,
      default: () => null
    },
    /**
     * @Description：显示名称
     */
    valueDisplay: {
      type: String,
      default: () => ''
    },
    /**
     * @Description：true: 禁用
     */
    disabled: {
      type: Boolean,
      default: () => false
    },
    /**
     * @Description：true: 从所有仓库列表查询
     */
    flagDataAll: {
      type: Boolean,
      default: () => false
    }
  },

  created() {
    if (this.flagDataAll) {
      this.vuexType = 'warehouseAll'
      this.vuexGetKey = 'warehouseAll'
      this.keyLabel = 'name'
    }
  },

  data() {
    return {
      vuexType: 'warehouseByUserId',
      keyLabel: 'warehouseName',
      vuexGetKey: 'warehouseListByUser',
    }
  },
  computed: {
  },
  methods: {
    // 选中项改变
    _change(selectItem) {
      this.$emit('change',  selectItem)
    },

    // 查询条件
    _dataFilter(list ) {
      return list.filter(find => {
        if (global.strings.isNotBlank(this.idNe) && find.id == this.idNe) {
          return false
        }
        if (global.strings.isNotBlank(this.flagCenter) && find.flagCenter != this.flagCenter) {
          return false
        }
        return true
      })
    },

    // 实例
    getInst() {
      return this.$refs.controlInst
    },

    // 聚焦搜索框
    focus() {
      this.getInst().focus()
    },
  },
}
</script>
